package com.xuecheng.content.feignclient;

import com.xuecheng.content.feignclient.model.CourseIndex;
import feign.hystrix.FallbackFactory;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * @author 26455
 * @version 1.0
 * @description TODO
 * @date 2023/2/22 9:43
 */
@FeignClient(value = "search", fallbackFactory = SearchServiceClient.SearchServiceClientFallbackFactory.class)
public interface SearchServiceClient {
    @PostMapping("/search/index/course")
    public Boolean add(@RequestBody CourseIndex courseIndex);

    @Slf4j
    @Component
    public class SearchServiceClientFallbackFactory implements FallbackFactory<SearchServiceClient> {

        @Override
        public SearchServiceClient create(Throwable throwable) {

            return new SearchServiceClient() {
                @Override
                public Boolean add(CourseIndex courseIndex) {
                    log.debug("添加课程索引失败");
                    return null;
                }
            };
        }
    }
}
